#include "attack.h"
#include "config.h"

attack::attack()
{
    m_attack.load(":/picture/images/bullet_big.png");
    m_x=(GAME_WIDTH-m_attack.width())*0.5;
    m_y=0;
    m_free=true;
    m_speed=ATTACK_SPEED;
    m_Rect.setWidth(m_attack.width());
    m_Rect.setHeight(m_attack.height());
    m_Rect.moveTo(m_x,m_y);
}

void attack::updatePosition(int dir)
{
    if(m_free){return;}
    switch (dir)
    {
    case 0:{m_y += m_speed;break;}                  //往下发射
    case 1:{m_x += m_speed;m_y += m_speed;break;}   //往右下角发射
    case 2:{m_x -= m_speed;m_y += m_speed;break;}   //往左下角发射
    }
     m_Rect.moveTo(m_x,m_y);
     if(m_y>=GAME_HEIGHT+m_Rect.height()||m_x>=GAME_WIDTH)
     {
         m_free=true;
     }
}

